/*
 * @Author: Gavin
 * @Date: 2018-09-07 10:29:17
 * @LastEditors: Gavin
 * @LastEditTime: 2018-09-07 10:29:17
 * @Description:
 */
let webpackDev = require('webpack-dev-middleware')

module.exports = (compiler, opts) => {
    const middleware = webpackDev(compiler, opts)
    return async (ctx, next) => {
        await middleware(ctx.req, {
            end: (content) => {
                ctx.body = content
            },
            setHeader: (name, value) => {
                ctx.set(name, value)
            }
        }, next)
    }
}
